package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GaUser;
import com.ruoyi.system.service.IGaUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户信息Controller
 * 
 * @author wzp
 * @date 2021-11-18
 */
@RestController
@RequestMapping("/kyga/user")
public class GaUserController extends BaseController
{
    @Autowired
    private IGaUserService gaUserService;

    /**
     * 查询用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('kyga:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(GaUser gaUser)
    {
        startPage();
        List<GaUser> list = gaUserService.selectGaUserList(gaUser);
        return getDataTable(list);
    }

    /**
     * 导出用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('kyga:user:export')")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GaUser gaUser)
    {
        List<GaUser> list = gaUserService.selectGaUserList(gaUser);
        ExcelUtil<GaUser> util = new ExcelUtil<GaUser>(GaUser.class);
        return util.exportExcel(list, "用户信息数据");
    }

    /**
     * 获取用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('kyga:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gaUserService.selectGaUserById(id));
    }

    /**
     * 新增用户信息
     */
    @PreAuthorize("@ss.hasPermi('kyga:user:add')")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GaUser gaUser)
    {
        return toAjax(gaUserService.insertGaUser(gaUser));
    }

    /**
     * 修改用户信息
     */
    @PreAuthorize("@ss.hasPermi('kyga:user:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GaUser gaUser)
    {
        return toAjax(gaUserService.updateGaUser(gaUser));
    }

    /**
     * 删除用户信息
     */
    @PreAuthorize("@ss.hasPermi('kyga:user:remove')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gaUserService.deleteGaUserByIds(ids));
    }

    /**
     * 更新学生密码
     */
    @PostMapping("/UpdateUserPassword")
    @Log(title = "更新学生密码", businessType = BusinessType.INSERT)
    public AjaxResult updateUserPassword(GaUser user) {
        return toAjax(gaUserService.updateGaUser(user));
    }
}
